package butines.game.lastcolony;

import java.awt.Color;
import java.awt.Font;
import java.awt.Graphics2D;

import butines.common.game.StateBasedGame;
import butines.core.GameAction;
import butines.core.gui.style.HAlign;
import butines.core.gui.style.Text;
import butines.game.lastcolony.entities.Game;
import butines.game.lastcolony.entities.Maps;
import butines.game.lastcolony.screen.GameInterfaceScreen;
import butines.game.lastcolony.screen.GameStartScreen;
import butines.game.lastcolony.screen.MissionScreen;

public class LastColony extends StateBasedGame {

	public static void main(String[] args) {
 		new LastColony().startup();
	}
	
	private GameAction fullscreen = new GameAction("FullScren", GameAction.DETECT_INITAL_PRESS_ONLY);
	private GameAction quit = new GameAction("Sair", GameAction.DETECT_INITAL_PRESS_ONLY);
	
	private GameStartScreen gameStartScreen;
	private MissionScreen missionScreen;
	private GameInterfaceScreen gameInterfaceScreen; 
	private SinglePlayer singlePlayer;
	private MultiPlayer multiPlayer;
	
	private Game game = new Game(this);
	private Maps maps = new Maps();
	
	private Text textSystem = new Text(new Font("Consolas",  Font.BOLD,  12), HAlign.LEFT, Color.WHITE);
	
	@Override
	public void init() {
		
		defineActionKey(fullscreen, KEY_F1);
		defineActionKey(quit, KEY_ESC);

		setFrameRate(120);
		setWindow(640, 480);
		setSystemCursorVisible(true);
		setRelativeMouseMode(false);
		
		game.setCanvasWidth(480);
		game.setCanvasHeight(400);
		
		gameStartScreen = new GameStartScreen(this);
		
		missionScreen = new MissionScreen(this);
		
		gameInterfaceScreen = new GameInterfaceScreen(this);

		singlePlayer = new SinglePlayer(this);
		
		multiPlayer = new MultiPlayer(this);
		
		gameStartScreen.show();
	}
	
	@Override
	public void destroy() {

	}
	
	private void toggleFullScreen() {
	    if (isFullScreen()) {
            setWindow(640, 480);
        } else {
            setFullScreen(640, 480);
        }
	}

	@Override
	public void preUpdateState(float tpf) {

		if (fullscreen.isPressed()) {
		    toggleFullScreen();
		}
		
		if (quit.isPressed()) {
			shutdown();
		}

	}

	@Override
    protected void posRenderState(Graphics2D g2d) {
	    textSystem.draw(g2d, 0,  0, "FPS " + getFps());
	    textSystem.draw(g2d, 0, 20, "UPS " + getUps());
    }

    public GameStartScreen getGameStartScreen() {
		return gameStartScreen;
	}

	public MissionScreen getMissionScreen() {
		return missionScreen;
	}
	
	public GameInterfaceScreen getGameInterfaceScreen() {
		return gameInterfaceScreen;
	}

	public SinglePlayer getSinglePlayer() {
		return singlePlayer;
	}

    public Game getGame() {
        return game;
    }

    public Maps getMaps() {
        return maps;
    }

    public MultiPlayer getMultiPlayer() {
        return multiPlayer;
    }
	
}
